<template>
    <rx-layout>
        <div slot="center" style>
            <rx-fit :isheader="isheader">
                <div slot="toolheader" foldheader="true" foldbtn="false" border="false">
                    <div class="table-operator">
                        <rx-button
                            alias="infInboxMsgAdd"
                            :butn-icon="'plus'"
                            :butn-type="'primary'"
                            :show-no-right="true"
                            @click="add"
                        >{{$ti18('rxList.newBtn','新建')}}
                        </rx-button>
                        <a-dropdown v-if="removeEnable && selectedRowKeys.length > 0">
                            <rx-button
                                alias="infInboxDelete"
                                :butn-icon="'delete'"
                                :butn-type="'danger'"
                                :show-no-right="false"
                                @click="delByIds(selectedRowKeys)"
                            >{{$ti18('rxList.delBtn','删除')}}
                            </rx-button>
                        </a-dropdown>
                    </div>
                    <span class="search-btn-box" v-if="!isheader">
            <span class="search-btn" @click.stop="searchshow"><i class="iconfont iconguolv"></i>{{$ti18('rxList.leachBtn','过滤')}}</span>
          </span>
                </div>
                <div btnalign="right" slot="searchbar" v-if="fitSearch" @search="search" @cancel="cancel"
                     @close="closeSearchbar">
                    <a-form :layout="colLayout">
                        <a-row :gutter="24">
                            <a-col :span="colSpan">
                                <a-form-item :label="$ti18('rxList.title', '标题')">
                                    <a-input :placeholder="$ti18('rxList.title', '标题','','input')" v-model="queryParam.Q_MSG_TITLE__S_LK"/>
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('timeFrom','消息创建时间 从')">
                                    <a-date-picker
                                        style="width: 100%"
                                        :placeholder="i18n('createTime','请输入任务创建时间')"
                                        v-model="queryParam['Q_CREATE_TIME__D_GT']"
                                        format="YYYY-MM-DD"
                                    />
                                </a-form-item>
                            </a-col>
                            <a-col :span="colSpan">
                                <a-form-item :label="i18n('to','至')">
                                    <a-date-picker
                                        style="width: 100%"
                                        :placeholder="i18n('createTime','请输入任务创建时间')"
                                        v-model="queryParam['Q_CREATE_TIME__D_LT']"
                                        format="YYYY-MM-DD"
                                    />
                                </a-form-item>
                            </a-col>
                        </a-row>
                    </a-form>
                </div>
                <rx-grid
                    ref="table"
                    :bordered="isBorder"
                    :allowRowSelect="true"
                    :multiSelect="true"
                    :columns="columns"
                    :defaultPageSize="10"
                    url="/api-portal/portal/core/infInnerMsg/querySentMsg"
                    :queryParam="queryParam"
                    data-field="result.data"
                    :pageSizeOptions="['10', '30', '40']"
                    id-field="msgId"
                    @selectChange="onSelectChange"
                >
          <span slot="userList" slot-scope="{ text, record }">
            <span>
              <a-tag v-for="user in record.userList"><a-icon type="user"></a-icon>{{ user.name }}</a-tag>
            </span>
          </span>
                    <span slot="groupList" slot-scope="{ text, record }">
            <span>
              <a-tag v-for="group in record.groupList"><a-icon type="team"></a-icon>{{ group.name }}</a-tag>
            </span>
          </span>
                    <span slot="appId" slot-scope="{ text, record }">
             {{allApps[text]?$i18(allApps[text].appName,'应用名称'):$ti18('rxList.noAppName','无')}}
          </span>
                    <span slot="action" slot-scope="{ text, record }" class="actionIcons">
            <span @click.stop="readMessage(record)">{{i18n('list.view','查看')}}</span>
            <span v-if="removeEnable && showBtn(false)" @click="delByIds([record.msgId])">{{$ti18('rxList.delBtn','删除')}}</span>
          </span>
                </rx-grid>
                <div>
                    <a-drawer
                        :title="i18n('list.viewMsg','查看消息')"
                        placement="right"
                        :closable="false"
                        :visible="visible"
                        @close="onClose"
                        :width="400"
                    >
                        <ReadMessage :infInnerMsg="infInnerMsg" :isSender="true"></ReadMessage>
                    </a-drawer>
                </div>
            </rx-fit>
        </div>
    </rx-layout>
</template>

<script>
    import InfInboxApi from '@/api/portal/core/infInbox'
    import InfInnerMsgEdit from './InfInnerMsgEdit'
    import ReadMessage from './ReadMessage.vue'
    import {BaseList, Util} from "@lowcode/jpaas-common-lib"
    import {mapState} from 'vuex';

    export default {
        name: 'InfInboxList',
        mixins: [BaseList],
        components: {
            ReadMessage,
        },
        computed: {
            ...mapState({
                // 所属应用
                allApps: state => state.appSetting ? state.appSetting.allApps : {}
            }),
        },
        data() {
            return {
                columns: [
                    {
                        title: this.$ti18('rxList.index','序号'),
                        type: 'indexColumn',
                        width: 40,
                        dataIndex: 'serial',
                        scopedSlots: {customRender: 'serial'},
                    },
                    {title: this.$ti18('rxList.title','标题'), dataIndex: 'msgTitle', width: 180},
                    {title: this.i18n('form.addressee','收信人'), dataIndex: 'userList', width: 140, scopedSlots: {customRender: 'userList'}},
                    {title: this.i18n('form.reSection','收信组'), dataIndex: 'groupList', width: 140, scopedSlots: {customRender: 'groupList'}},
                    {
                        title: this.i18n('form.app','所属应用'),
                        dataIndex: 'appId',
                        width: 140,
                        sortField: 'APP_ID_',
                        scopedSlots: {customRender: 'appId'}
                    },
                    {title: this.i18n('form.sendTime','发送时间'), dataIndex: 'createTime', width: 120},
                    {title: this.$ti18('rxList.action','操作'), width: 80, dataIndex: 'action', scopedSlots: {customRender: 'action'}},
                ],
                component: InfInnerMsgEdit,
                comment: this.i18n('list.shortMsg','内部短消息'),
                widthHeight: ['800px', '600px'],
                visible: false,
                infInnerMsg: {},
            }
        },
        methods: {
            i18n(name, text, key) {
                return this.$ti18(name, text, "infInbox", key);
            },
            delByIds(msgIds) {
                InfInboxApi.delSentMsg({msgIds: msgIds.join(',')}).then((res) => {
                    this.$refs.table.loadData()
                })
                return
            },
            getListByParams(parameter) {
                return InfInboxApi.querySentMsg(parameter)
            },
            readMessage(record) {
                this.visible = true
                this.infInnerMsg = record
            },
            onClose() {
                this.visible = false
            },
            search() {
                this.$refs.table.loadData()
            },
            cancel() {
                this.resetSearch()
            },
            closeSearchbar() {
                //关闭过滤弹窗；（点击X触发）
                this.fitSearch = false;
            },

        },
    }
</script>
<style scoped>

</style>

